/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.ucm;

import assignment_cp3120.auth.Authenticate;
import assignment_cp3120.deleteUser.DeleteUserModel;
import assignment_cp3120.deleteUser.DeleteUserView;
import assignment_cp3120.startup.StartupView;
import assignment_cp3120.user.UserModel;
import assignment_cp3120.user.UserView;
import assignment_cp3120.view.MainFrame;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

/**
 * 1. System shows user screen;
 * @author Richard Irons
 */

public class UCUser implements UseCaseController{
    private UserView view;
    private UserModel model;
    private MainFrame mainView;

    /**
     * Constructor for the User uc, sets model, view and frame to the inputs
     * @param model
     * @param view
     * @param mainView
     */
    public UCUser(UserModel model, UserView view, MainFrame mainView) {
        this.model = model;
        this.view = view;
        this.mainView = mainView;
        view.buttonListener(this);
    }
    /**
     * Defulat constructor, calls Constructor(model,view,frame) with new inputs for each
     */
    public UCUser(){
        this(new UserModel(), new UserView(), new MainFrame());
    }
    /**
     * Starts the use case. Sets the contents of the mainFrame to the view and sets the subtitle
     */
    public void run() {
        mainView.setContents(view);
        mainView.setSubTitle(new JLabel("Welcome user: " + Authenticate.getCurUser().getFirstname()));                
    }
    /**
     * Action preformed for the buttons pressed
     * @param e
     * Triggering event
     */
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals(model.DELETE)){
            DeleteUserModel deleteUserModel = new DeleteUserModel();
            DeleteUserView deleteUserView = new DeleteUserView(deleteUserModel);
            UCDeleteUser deleteUser = new UCDeleteUser(deleteUserModel, deleteUserView, mainView);
            deleteUser.run();
        }
        if(e.getActionCommand().equals(model.LOGOUT)){
            mainView.setSubTitle(new JLabel());
            mainView.setContents(new StartupView().getContents());
            
        }
    }
    

}
